<template>
  <div :class="background ? 'normal' : 'blue'">
    <a-page-header>
      <template slot="title">
        <a-icon type="arrow-left" v-if="back" @click="() => $router.go(-1)" />
        <span class="home" @click="backHome">{{ title }}</span>
      </template>
      <template slot="extra">
        <template v-if="token">
          <a-popover trigger="click">
            <template slot="content">
              <div class="header_item" @click="toPersonal">个人中心</div>
              <div class="header_item" @click="toMessage">消息提醒</div>
              <div class="header_item" @click="loginOut">退出</div>
            </template>
            <!-- <a-avatar :size="32" icon="user" style="cursor: pointer" /> -->
            <div class="user_name">{{ user.name }}</div>
          </a-popover>
        </template>
        <template v-else>
          <div @click="toLogin" class="login_btn">登录</div>
        </template>
      </template>
    </a-page-header>
  </div>
</template>
<script>
export default {
  name: "headComponent",
  props: ["title", "background", "back"],
  data() {
    return {
      token: "",
      user: {
        name: "",
      },
    };
  },
  methods: {
    backHome() {
      this.$router.push("/home");
    },
    toPersonal() {
      this.$router.push("/profile");
    },
    toLogin() {
      window.location = '/grade-evaluation-management/'
      // this.$router.push("/index");
    },
    loginOut() {
      sessionStorage.removeItem('isLoadScript')
      this.$storejs.remove("token");
      this.$storejs.remove("userInfo");
      // this.$router.push("/index");
      window.location = '/grade-evaluation-management/'
    },
    toMessage() {
      this.$router.push("/message");
    }
  },
  created() {
    this.token = this.$storejs.get("token");
    this.user.name = this.$storejs.get("userInfo").user.userName;
  },
  mounted() {},
};
</script>
<style lang="less" scoped>
/* 公共头部 */
/deep/ .anticon {
  cursor: pointer;
}
.home {
  cursor: pointer;
  margin-left: 12px;
}
.login_btn {
  cursor: pointer;
  line-height: 32px;
  font-size: 16px;
}
.header_item {
  text-align: center;
  cursor: pointer;
  color: #5c8de9;
  padding: 5px 0;
  font-size: 16px;
}
.user_name {
  font-size: 16px;
  color: #595959;
  line-height: 32px;
  cursor: pointer;
}
.blue {
  /deep/ .ant-page-header {
    background: #5c8de9;
  }
  /deep/ .ant-page-header-heading-title {
    color: #fff;
  }
  .login_btn {
    color: #fff;
  }
  .user_name {
    color: #fff;
  }
}
.normal {
  .login_btn {
    color: #595959;
  }
}
</style>